package client.gui.panels;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import com.toedter.calendar.JCalendar;

import controllers.ControllerIF;
import java.awt.Component;
import java.util.Calendar;
import java.awt.Button;
import java.awt.FlowLayout;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;
import java.awt.BorderLayout;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Reports extends JPanel implements PanelIF, ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Instance of the panel's controller
	 */
	private ControllerIF panelController;
	private JCalendar calendar;
	private JTextField periodicReportFromTextField;
	private JTextField periodicReportToTextField;
	private JTextField medianPeriodicTextField;
	private JTextField approvedTimeDurationTextField;
	private JTextField additionalTimeTextField;
	private JTextField medianDelayReportTextField;
	private JTable periodicStandartDeviationTable;
	private JTable delaysStandartDeviationTable;


	/**
	 * Create the frame.
	 */
	public Reports() {
		initGui();
	}
	
	/**
	 * Initialize the user interface
	 */
	public void initGui() {
		setBorder(new EmptyBorder(5, 5, 5, 5));
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		calendar = new JCalendar();
		
		add(Box.createVerticalStrut(15));
				
				JPanel panel = new JPanel();
				panel.setBorder(new TitledBorder(null, "Periodic report", TitledBorder.LEADING, TitledBorder.TOP, null, null));
				add(panel);
				panel.setLayout(new BorderLayout(0, 0));
				
				JPanel panel_1 = new JPanel();
				panel.add(panel_1);
				panel_1.setAlignmentX(Component.LEFT_ALIGNMENT);
				panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.Y_AXIS));
						
								// Dates panel
								JPanel periodPanel = new JPanel();
								periodPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
								panel_1.add(periodPanel);
								periodPanel.setMaximumSize(new Dimension(450,110));
								periodPanel.setLayout(new BoxLayout(periodPanel, BoxLayout.X_AXIS));		
								periodPanel.add(Box.createHorizontalStrut(20));		
								JLabel lblPeriod = new JLabel("Periodic report:");
								lblPeriod.setFont(new Font("Arial", Font.PLAIN, 12));
								periodPanel.add(lblPeriod);
								
								Component horizontalStrut = Box.createHorizontalStrut(20);
								periodPanel.add(horizontalStrut);
								
								periodicReportFromTextField = new JTextField();
								periodicReportFromTextField.setMaximumSize(new Dimension(30,20));
								periodPanel.add(periodicReportFromTextField);
								periodicReportFromTextField.setColumns(10);
								
								Component horizontalStrut_1 = Box.createHorizontalStrut(20);
								periodPanel.add(horizontalStrut_1);
								
								JLabel lblNewLabel = new JLabel(" - ");
								periodPanel.add(lblNewLabel);
								
								Component horizontalStrut_2 = Box.createHorizontalStrut(20);
								periodPanel.add(horizontalStrut_2);
								
								periodicReportToTextField = new JTextField();
								periodicReportToTextField.setMaximumSize(new Dimension(30,20));
								periodPanel.add(periodicReportToTextField);
								periodicReportToTextField.setColumns(10);
								
								Component horizontalGlue = Box.createHorizontalGlue();
								periodPanel.add(horizontalGlue);
						
						Component verticalStrut_1 = Box.createVerticalStrut(20);
						panel_1.add(verticalStrut_1);
						
						JPanel medianPanel = new JPanel();
						medianPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
						medianPanel.setMaximumSize(new Dimension(450,110));
						panel_1.add(medianPanel);
						medianPanel.setLayout(new BoxLayout(medianPanel, BoxLayout.X_AXIS));
						
						Component horizontalStrut_3 = Box.createHorizontalStrut(20);
						medianPanel.add(horizontalStrut_3);
						
						JLabel medianLbl = new JLabel("Median:");
						medianPanel.add(medianLbl);
						
						Component horizontalStrut_4 = Box.createHorizontalStrut(20);
						medianPanel.add(horizontalStrut_4);
						
						medianPeriodicTextField = new JTextField();
						medianPeriodicTextField.setMaximumSize(new Dimension(30,20));
						medianPanel.add(medianPeriodicTextField);
						medianPeriodicTextField.setColumns(10);
						
						Component horizontalGlue_8 = Box.createHorizontalGlue();
						medianPanel.add(horizontalGlue_8);
		
		Component verticalStrut = Box.createVerticalStrut(20);
		panel_1.add(verticalStrut);
		
		JPanel deviationPanel = new JPanel();
		deviationPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
		deviationPanel.setMaximumSize(new Dimension(450,110));
		panel_1.add(deviationPanel);
		deviationPanel.setLayout(new BoxLayout(deviationPanel, BoxLayout.X_AXIS));
		
		Component horizontalStrut_6 = Box.createHorizontalStrut(20);
		deviationPanel.add(horizontalStrut_6);
		
		JLabel lblNewLabel_1 = new JLabel("Standard deviation:");
		deviationPanel.add(lblNewLabel_1);
		
		periodicStandartDeviationTable = new JTable();
		periodicStandartDeviationTable.setModel(new DefaultTableModel(
			new Object[][] {
				{"1", "1"},
				{"2", "1"},
				{"3", "1"},
				{"4", "0"},
				{"5", "2"},
			},
			new String[] {
				"number", "New column"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		deviationPanel.add(periodicStandartDeviationTable);
		
		JPanel panel_4 = new JPanel();
		panel_4.setBorder(new TitledBorder(null, "Preformance report", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		add(panel_4);
		panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.X_AXIS));
		
		JPanel panel_2 = new JPanel();
		panel_4.add(panel_2);
		panel_2.setAlignmentX(Component.LEFT_ALIGNMENT);
		panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.Y_AXIS));
		
		JPanel durationPanel = new JPanel();
		durationPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
		panel_2.add(durationPanel);
		durationPanel.setLayout(new BoxLayout(durationPanel, BoxLayout.X_AXIS));
		
		Component horizontalStrut_12 = Box.createHorizontalStrut(20);
		durationPanel.add(horizontalStrut_12);
		
		JLabel durationLbl = new JLabel("Duration of approved time extension:");
		durationPanel.add(durationLbl);
		
		Component horizontalStrut_13 = Box.createHorizontalStrut(20);
		durationPanel.add(horizontalStrut_13);
		
		approvedTimeDurationTextField = new JTextField();
		approvedTimeDurationTextField.setMaximumSize(new Dimension(30, 20));
		approvedTimeDurationTextField.setColumns(10);
		durationPanel.add(approvedTimeDurationTextField);
		
		Component horizontalGlue_6 = Box.createHorizontalGlue();
		durationPanel.add(horizontalGlue_6);
		
		Component verticalStrut_6 = Box.createVerticalStrut(20);
		panel_2.add(verticalStrut_6);
		
		JPanel addTimePanel = new JPanel();
		addTimePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
		panel_2.add(addTimePanel);
		addTimePanel.setLayout(new BoxLayout(addTimePanel, BoxLayout.X_AXIS));
		
		Component horizontalStrut_15 = Box.createHorizontalStrut(20);
		addTimePanel.add(horizontalStrut_15);
		
		JLabel addLbl = new JLabel("Addional time to ticket:");
		addTimePanel.add(addLbl);
		
		Component horizontalStrut_16 = Box.createHorizontalStrut(20);
		addTimePanel.add(horizontalStrut_16);
		
		additionalTimeTextField = new JTextField();
		additionalTimeTextField.setMaximumSize(new Dimension(30, 20));
		additionalTimeTextField.setColumns(10);
		addTimePanel.add(additionalTimeTextField);
		
		Component horizontalGlue_5 = Box.createHorizontalGlue();
		addTimePanel.add(horizontalGlue_5);
		
		Component verticalStrut_4 = Box.createVerticalStrut(20);
		panel_2.add(verticalStrut_4);
		
		JPanel panel_5 = new JPanel();
		panel_5.setBorder(new TitledBorder(null, "Delays report", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		add(panel_5);
		panel_5.setLayout(new BoxLayout(panel_5, BoxLayout.X_AXIS));
		
		JPanel panel_3 = new JPanel();
		panel_5.add(panel_3);
		panel_3.setAlignmentX(Component.LEFT_ALIGNMENT);
		panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.Y_AXIS));
		
		JPanel madianPanel2 = new JPanel();
		madianPanel2.setAlignmentX(Component.LEFT_ALIGNMENT);
		panel_3.add(madianPanel2);
		madianPanel2.setLayout(new BoxLayout(madianPanel2, BoxLayout.X_AXIS));
		
		Component horizontalStrut_22 = Box.createHorizontalStrut(20);
		madianPanel2.add(horizontalStrut_22);
		
		JLabel label = new JLabel("Median:");
		madianPanel2.add(label);
		
		Component horizontalStrut_23 = Box.createHorizontalStrut(20);
		madianPanel2.add(horizontalStrut_23);
		
		medianDelayReportTextField = new JTextField();
		madianPanel2.add(medianDelayReportTextField);
		medianDelayReportTextField.setMaximumSize(new Dimension(30, 20));
		medianDelayReportTextField.setColumns(10);
		
		Component horizontalGlue_3 = Box.createHorizontalGlue();
		madianPanel2.add(horizontalGlue_3);
		
		Component verticalStrut_7 = Box.createVerticalStrut(20);
		panel_3.add(verticalStrut_7);
		
		JPanel standartPanel2 = new JPanel();
		standartPanel2.setAlignmentX(Component.LEFT_ALIGNMENT);
		panel_3.add(standartPanel2);
		standartPanel2.setLayout(new BoxLayout(standartPanel2, BoxLayout.X_AXIS));
		
		Component horizontalStrut_25 = Box.createHorizontalStrut(20);
		standartPanel2.add(horizontalStrut_25);
		
		JLabel label_3 = new JLabel("Standard deviation:");
		standartPanel2.add(label_3);
		
		delaysStandartDeviationTable = new JTable();
		delaysStandartDeviationTable.setModel(new DefaultTableModel(
			new Object[][] {
				{"1", "0"},
				{"2", "2"},
				{"3", "0"},
				{"4", "2"},
				{"5", "1"},
			},
			new String[] {
				"New column", "New column"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				true, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		standartPanel2.add(delaysStandartDeviationTable);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		 
	}

	/**
	 * set local parameter to hold the controller reference
	 * @param cif Controller interface
	 */
	public void setController(ControllerIF cif) {
		panelController = cif;		
	}

	public void setPeriodicReportFromTextField(String periodicReportFromTextField) {
		this.periodicReportFromTextField.setText(periodicReportFromTextField);
	}

	public void setPeriodicReportToTextField(String periodicReportToTextField) {
		this.periodicReportToTextField.setText(periodicReportToTextField);
	}

	public void setMedianPeriodicTextField(String medianPeriodicTextField) {
		this.medianPeriodicTextField.setText(medianPeriodicTextField);
	}

	public void setApprovedTimeDurationTextField(String approvedTimeDurationTextField) {
		this.approvedTimeDurationTextField.setText(approvedTimeDurationTextField);
	}

	public void setAdditionalTimeTextField(String additionalTimeTextField) {
		this.additionalTimeTextField.setText(additionalTimeTextField);
	}

	public void setMedianDelayReportTextField(String medianDelayReportTextField) {
		this.medianDelayReportTextField.setText(medianDelayReportTextField);
	}
}
